package com.wangcanxuan.www.controller.Impl;

import com.wangcanxuan.www.controller.TribeController;
import com.wangcanxuan.www.entity.dto.ResultInfo;
import com.wangcanxuan.www.entity.po.Tribe;
import com.wangcanxuan.www.entity.po.User;
import com.wangcanxuan.www.proxy.ServiceProxy;
import com.wangcanxuan.www.service.Impl.TribeServiceImpl;
import com.wangcanxuan.www.service.TribeService;

import java.util.List;

/**
 * 部落界面的Controller实现类
 *
 * @author HHLJ
 * @date 2022/03/28
 */
public class TribeControllerImpl implements TribeController {
    private final TribeService tribeService = ServiceProxy.getProxyInstance(TribeServiceImpl.class);


    @Override
    public ResultInfo<String> createTribe(User user, String tribeName) {
        ResultInfo<String> resultInfo = tribeService.createTribe(user, tribeName);
        if (resultInfo.isSuccess()) {
            resultInfo.setMessage("创建部落成功！");
        }
        return resultInfo;
    }

    @Override
    public ResultInfo<List<Tribe>> selectAllCampTribeList(int campId, int count) {
        return tribeService.selectAllCampTribeList(campId, count);
    }

    @Override
    public ResultInfo<List<Tribe>> selectSearchTribeList(int campId, String tribeName, int pageCount) {
        return tribeService.selectSearchTribeList(campId, tribeName, pageCount);
    }

    @Override
    public ResultInfo<Tribe> selectTribeByTribeId(String tribeId) {
        return tribeService.selectTribeByTribeId(tribeId);
    }

    @Override
    public ResultInfo<List<User>> selectUserListByGenderAndTribeId(String tribeId, String searchName, String gender, int pageCount) {
        return tribeService.selectUserListByGenderAndTribeId(tribeId, searchName, gender, pageCount);
    }


    @Override
    public ResultInfo<String> kickTribe(User user, String chooseName) {
        ResultInfo<String> resultInfo = tribeService.kickTribe(user, chooseName);
        if (resultInfo.isSuccess()) {
            resultInfo.setMessage("已将" + chooseName + "踢出部落");
        }
        return resultInfo;
    }

    @Override
    public ResultInfo<Long> selectNumbersForTribe(String tribeId) {
        return tribeService.selectNumbersForTribe(tribeId);
    }

    @Override
    public ResultInfo<String> exitTribe(User user) {
        ResultInfo<String> resultInfo = tribeService.exitTribe(user);
        if (resultInfo.isSuccess()) {
            resultInfo.setMessage("退出部落成功！");
        }
        return tribeService.exitTribe(user);
    }

    @Override
    public ResultInfo<String> coinToCoins(User user, int coinToCoins) {
        ResultInfo<String> resultInfo = tribeService.coinToCoins(user, coinToCoins);
        resultInfo.setMessage("感谢你为部落贡献！");
        return resultInfo;
    }

    @Override
    public ResultInfo<String> coinToPower(Tribe tribe, int coinToPower) {
        ResultInfo<String> resultInfo = tribeService.coinToPower(tribe, coinToPower);
        resultInfo.setMessage("交换战力成功！");
        return resultInfo;
    }

    @Override
    public ResultInfo<String> levelUp(Tribe tribe) {
        ResultInfo<String> resultInfo = tribeService.levelUp(tribe);
        resultInfo.setMessage("升级成功！");
        return resultInfo;
    }

    @Override
    public ResultInfo<String> dismissTribe(String tribeId) {
        ResultInfo<String> resultInfo = tribeService.dismissTribe(tribeId);
        if (resultInfo.isSuccess()) {
            resultInfo.setMessage("解散部落成功！");
        }
        return resultInfo;
    }

    @Override
    public ResultInfo<String> tribeSignIn(User user) {
        ResultInfo<String> resultInfo = tribeService.tribeSignIn(user);
        if (resultInfo.isSuccess()) {
            resultInfo.setMessage("签到成功，感谢您为部落做出的贡献!");
        }
        return resultInfo;
    }

    @Override
    public ResultInfo<String> permissionGive(User user, String chooseName, int roleId) {

        ResultInfo<String> resultInfo = tribeService.permissionGive(user, chooseName, roleId);
        if (resultInfo.isSuccess()) {
            resultInfo.setMessage("修改权限成功！");
        }
        return resultInfo;
    }
}
